home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / sounds / tools / startracker-1.2.lha / BootNTSC.asm < prev    next >
Assembly Source File  |  1990-05-22  |  7KB  |  313 lines

  1.     OPT c+,l-,o+
  2.  
  3. *********************
  4. *                   *
  5. *  BootNTSC 1.0     *
  6. *                   *
  7. *  by Nico François *
  8. *********************
  9.  
  10.     incdir "INCLUDE:"
  11.     include "exec/types.i"
  12.     include "exec/execbase.i"
  13.     include "exec/memory.i"
  14.     include "exec/resident.i"
  15.     include "exec/exec_lib.i"
  16.     include "graphics/gfxbase.i"
  17.     include "graphics/graphics_lib.i"
  18.     include "libraries/dos_lib.i"
  19.  
  20. NULL    equ    0
  21.  
  22.     movem.l d0/a0,-(a7)
  23.     move.l ($4).w,a6
  24.     lea DosName(PC),a1
  25.     jsr _LVOOldOpenLibrary(a6)                ; open DOS
  26.     lea DOSBase(PC),a1
  27.     move.l d0,(a1)
  28.     move.l d0,a6
  29.     jsr _LVOOutput(a6)                        ; get stdout
  30.     lea stdout(PC),a1
  31.     move.l d0,(a1)
  32.     lea header.txt(PC),a0                    ; print header to console
  33.     move.l #header.len,d3
  34.     bsr puts
  35.  
  36.     move.w $DFF004,d0                            ; check for new 1Mb Agnus
  37.     and.w #$2000,d0
  38.     bne.s ok1MbAgnus
  39.     addq.w #8,a7
  40.     lea oldagnus.txt(PC),a0                    ; if not available print
  41.     move.l #oldagnus.len,d3                    ; message
  42.     move.l ($4).w,a6
  43.     bra putsandexit
  44. ok1MbAgnus:
  45.     movem.l (a7)+,d0/a0                        ; get command line back
  46.  
  47.     move.l ($4).w,a6
  48.     move.b #0,0(a0,d0.w)                        ; zero terminated
  49. cmdloop:
  50.     move.b (a0)+,d0                            ; look for 'I' or 'R'
  51.     beq.s template
  52.     cmp.b #'i',d0
  53.     beq.s install
  54.     cmp.b #'I',d0
  55.     beq.s install
  56.     cmp.b #'r',d0
  57.     beq quit
  58.     cmp.b #'R',d0
  59.     beq quit
  60.     bra.s cmdloop
  61.  
  62. template:                                        ; print usage line
  63.     lea usage.txt(PC),a0
  64.     move.l #usage.len,d3
  65.     bra putsandexit
  66.  
  67. install:
  68.     move.l ($4).w,a6
  69.     lea PortName(PC),a1
  70.     jsr _LVOFindPort(a6)                        ; find our port
  71.     tst.l d0
  72.     beq.s allocit
  73.     lea already.txt(PC),a0                    ; found, so already installed
  74.     move.l #already.len,d3
  75.     bra putsandexit
  76.  
  77. allocit:
  78.     move.l #BlockLen,d0
  79.     move.l #MEMF_CHIP,d1                        ; allocate memory for reset code
  80.     jsr _LVOAllocMem(a6)                        ; must be in CHIP !!
  81.     tst.l d0
  82.     bne.s memok
  83.     lea nomem.txt(PC),a0                        ; out of memory ???
  84.     move.l #nomem.len,d3
  85.     bra putsandexit
  86.  
  87. memok:
  88.     move.l d0,a5                                ; a5 holds address of copy
  89.     lea StartBlock(PC),a0
  90.     move.l d0,a1
  91.     move.l #BlockLen,d0
  92.     jsr _LVOCopyMem(a6)                        ; copy block to allocated memory
  93.     move.w #$4000,$DFF09A                    ; DISABLE
  94.     addq.b #1,IDNestCnt(a6)
  95.     lea RomTagPtrs-StartBlock(a5),a0
  96.     move.l KickTagPtr(a6),4(a0)            ; old romtag pointer in array
  97.     beq.s yestag
  98.     bset #7,4(a0)                                ; set bit if there are more
  99. yestag:
  100.     move.l a0,KickTagPtr(a6)                ; pointer to our array
  101.     lea RomTag-StartBlock(a5),a1
  102.     move.l a1,(a0)                                ; fill in our romtag pointer
  103.  
  104.     lea myMemList-StartBlock(a5),a1        ; init memlist and put in
  105.     move.l a5,ML_SIZE+ME_ADDR(a1)            ; KickMemPtr list to protect
  106.     move.l KickMemPtr(a6),d0                ; our memory
  107.     move.l d0,LN_SUCC(a1)
  108.     move.l a1,KickMemPtr(a6)
  109. inittag:
  110.     lea RomTag-StartBlock(a5),a1            ; init romtag
  111.     move.l a1,RT_MATCHTAG(a1)
  112.     lea RT_SIZE(a1),a2
  113.     move.l a2,RT_ENDSKIP(a1)
  114.     lea TagName-StartBlock(a5),a2
  115.     move.l a2,RT_NAME(a1)
  116.     move.l a5,RT_INIT(a1)
  117.     jsr _LVOSumKickData(a6)                    ; calculate checksum
  118.     move.l d0,KickCheckSum(a6)
  119.     lea Port-StartBlock(a5),a1                ; init and add our port
  120.     moveq #0,d0
  121.     move.l d0,(a1)
  122.     move.l d0,LN_PRED(a1)
  123.     lea PortName-StartBlock(a5),a0
  124.     move.l a0,LN_NAME(a1)
  125.     jsr _LVOAddPort(a6)
  126.     subq.b #1,IDNestCnt(a6)                    ; ENABLE
  127.     bge.s noenable
  128.     move.w #$C000,$DFF09A
  129. noenable:
  130.     lea installed.txt(PC),a0                ; inform user of installation
  131.     move.l #installed.len,d3
  132.     bra.s putsandexit
  133.  
  134. quit:
  135.     lea PortName(PC),a1                        ; are we already installed ?
  136.     jsr _LVOFindPort(a6)
  137.     tst.l d0
  138.     bne.s portfound
  139.     lea nohandler.txt(PC),a0                ; no, can't quit then
  140.     move.l #nohandler.len,d3
  141.     bra.s putsandexit
  142.  
  143. portfound:
  144.     move.l d0,a4                                ; we found our port, so remove it
  145.     move.l a4,a1
  146.     jsr _LVORemPort(a6)
  147.  
  148.     move.w #$4000,$DFF09A                    ; DISABLE
  149.     addq.b #1,IDNestCnt(a6)
  150.  
  151.     lea myMemList-Port(a4),a1                ; remove our memlist from
  152.     lea KickMemPtr(a6),a0                    ; KickMemPtr list.
  153. nextnode:
  154.     move.l LN_SUCC(a0),d0
  155.     cmp.l d0,a1
  156.     beq.s foundmylist
  157.     move.l d0,a0
  158.     bra.s nextnode
  159. foundmylist:
  160.     move.l LN_SUCC(a1),d0
  161.     move.l d0,LN_SUCC(a0)    ; LN_SUCC = 0, so this also works for KickMemPtr
  162.  
  163.     move.l RomTagPtrs-Port+4(a4),KickTagPtr(a6)    ; old RomTag back
  164.     beq.s noclr2
  165.     bclr #7,KickCheckSum(a6)
  166. noclr2:
  167.     jsr _LVOSumKickData(a6)                    ; calculate checksum
  168.     move.l d0,KickCheckSum(a6)
  169.     subq.b #1,IDNestCnt(a6)                    ; ENABLE
  170.     bge.s noenable2
  171.     move.w #$C000,$DFF09A
  172. noenable2:
  173.     lea StartBlock-Port(a4),a1                ; free our copied block
  174.     move.l #BlockLen,d0
  175.     jsr _LVOFreeMem(a6)
  176.     lea removed.txt(PC),a0                    ; and inform the user
  177.     move.l #removed.len,d3
  178.  
  179. putsandexit:
  180.     bsr.s puts                                    ; print string in A0, length D3
  181.     move.l DOSBase(PC),a1
  182.     jsr _LVOCloseLibrary(a6)                ; close DOS and exit
  183.     moveq #0,d0
  184.     rts
  185.  
  186. * text-ptr in A0, length in D3
  187. puts:
  188.     move.l a6,-(a7)
  189.     move.l a0,d2
  190.     move.l stdout(PC),d1
  191.     move.l DOSBase(PC),a6
  192.     jsr _LVOWrite(a6)
  193.     move.l (a7)+,a6
  194.     rts
  195.  
  196. header.txt:
  197.     dc.b $9b,'1mBootNTSC 1.0 ',$9b,'0m',$9b,'33mby Nico François',$9b,'0m',10
  198. header.len equ *-header.txt
  199. oldagnus.txt:
  200.     dc.b 'You haven''t got the ECS 1Mb Agnus, so run out and buy one !',10,0
  201. oldagnus.len equ *-oldagnus.txt
  202. already.txt:
  203.     dc.b 'NTSC RomTag already installed !',10,0
  204. already.len equ *-already.txt
  205. usage.txt:
  206.     dc.b 'Usage: BootNTSC [I=INSTALL|R=REMOVE]',10,0
  207. usage.len equ *-usage.txt
  208. installed.txt:
  209.     dc.b 'NTSC RomTag installed, reset to activate !',10,0
  210. installed.len equ *-installed.txt
  211. nomem.txt:
  212.     dc.b 'No memory for RomTag (I only need about 250 bytes) !?!',10,0
  213. nomem.len equ *-nomem.txt
  214. nohandler.txt:
  215.     dc.b 'NTSC RomTag not installed !',10,0
  216. nohandler.len equ *-nohandler.txt
  217. removed.txt:
  218.     dc.b 'NTSC RomTag removed !',10,0
  219. removed.len equ *-removed.txt
  220. DosName:
  221.     dc.b 'dos.library',0
  222.     EVEN
  223. DOSBase:
  224.     dc.l 0
  225. stdout:
  226.     dc.l 0
  227.  
  228. *****************************************************************************
  229.  
  230. StartBlock:                                        ; this is the routine that will
  231.     movem.l d0-d7/a0-a6,-(a7)                ; be executed when we reset
  232.     move.l ($4).w,a6
  233.  
  234.     lea Port(PC),a1                            ; add our port to the system list
  235.     moveq #0,d0
  236.     move.l d0,(a1)
  237.     move.l d0,LN_PRED(a1)
  238.     lea PortName(PC),a0
  239.     move.l a0,LN_NAME(a1)
  240.     jsr _LVOAddPort(a6)
  241.  
  242. **** Put AMIGA in NTSC mode ****
  243.     lea GfxName(PC),a1
  244.     jsr _LVOOldOpenLibrary(a6)                ; open graphics.library
  245.     move.l d0,a1
  246.     move.w gb_DisplayFlags(a1),d0
  247.     and.b #%11111011,d0                        ; clear PAL flag
  248.     or.b  #%00000001,d0                        ; set NTSC flag
  249.     move.w d0,gb_DisplayFlags(a1)
  250.     move.w #200,gb_NormalDisplayRows(a1)    ; WorkBench 200 pixels high
  251.     or.b #LIBF_CHANGED,LIB_FLAGS(a1)
  252.     move.l a1,a2
  253.     jsr _LVOSumLibrary(a6)                    ; recalculate checksum
  254.     move.l a2,a1
  255.     jsr _LVOCloseLibrary(a6)
  256.     move.b #60,VBlankFrequency(a6)        ; change VBLANK
  257.     or.b #LIBF_CHANGED,LIB_FLAGS(a6)
  258.     jsr _LVOSumLibrary(a6)                    ; recalculate checksum
  259.  
  260. ************************
  261.     move.w #0,$dff1dc                            ; this one does all the magic
  262. ************************
  263.  
  264. endtag:
  265.     movem.l (sp)+,d0-d7/a0-a6                ; back to kickstart
  266.     rts
  267.  
  268. RomTagPtrs:
  269.     dc.l 0,0                                        ; array of RomTag pointers
  270. GfxName:
  271.     dc.b 'graphics.library',0
  272. PortName:
  273.     dc.b 'BootNTSC.port',0                    ; port name
  274. TagName:
  275.     dc.b 'NTSC-boot',0                        ; tag name
  276.     EVEN
  277.  
  278. myMemList:                                        ; memory list for reset protection
  279.     ds.b LN_SIZE
  280.     dc.w 1
  281.     dc.l NULL
  282.     dc.l BlockLen
  283.  
  284. Port:                                                ; our port structure
  285.     dc.l NULL
  286.     dc.l NULL
  287.     dc.b NT_MSGPORT
  288.     dc.b 0
  289.     dc.l NULL
  290.     dc.b 0
  291.     dc.b 0
  292.     dc.l NULL
  293.     ds.b 14
  294.  
  295. RomTag:                                            ; the RomTag to inform kickstart
  296.     dc.w RTC_MATCHWORD                        ; of what we want
  297.     dc.l NULL
  298.     dc.l NULL
  299.     dc.b RTF_COLDSTART
  300.     dc.b 1
  301.     dc.b 0
  302.     dc.b -10
  303.     dc.l NULL
  304.     dc.l NULL
  305.     dc.l 0
  306.  
  307. BlockLen equ *-StartBlock                    ; length of block to be copied
  308.  
  309. *****************************************************************************
  310.  
  311.     END
  312.  
  313.